// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//
#include <pollux/expression/register_special_form.h>
#include <pollux/expression/row_constructor.h>
#include <pollux/expression/special_form_registry.h>
#include <pollux/functions/sparksql/specialforms/at_least_n_non_nulls.h>
#include <pollux/functions/sparksql/specialforms/decimal_round.h>
#include <pollux/functions/sparksql/specialforms/from_json.h>
#include <pollux/functions/sparksql/specialforms/get_struct_field.h>
#include <pollux/functions/sparksql/specialforms/make_decimal.h>
#include <pollux/functions/sparksql/specialforms/spark_cast_expr.h>

namespace kumo::pollux::functions {
    void registerSparkSpecialFormFunctions() {
        POLLUX_REGISTER_VECTOR_FUNCTION(
            udf_concat_row, exec::RowConstructorCallToSpecialForm::kRowConstructor);
    }

    namespace sparksql {
        void registerSpecialFormGeneralFunctions(const std::string &prefix) {
            exec::registerFunctionCallToSpecialForms();
            exec::registerFunctionCallToSpecialForm(
                MakeDecimalCallToSpecialForm::kMakeDecimal,
                std::make_unique<MakeDecimalCallToSpecialForm>());
            exec::registerFunctionCallToSpecialForm(
                DecimalRoundCallToSpecialForm::kRoundDecimal,
                std::make_unique<DecimalRoundCallToSpecialForm>());
            exec::registerFunctionCallToSpecialForm(
                AtLeastNNonNullsCallToSpecialForm::kAtLeastNNonNulls,
                std::make_unique<AtLeastNNonNullsCallToSpecialForm>());
            registerSparkSpecialFormFunctions();
            registerFunctionCallToSpecialForm(
                "cast", std::make_unique<SparkCastCallToSpecialForm>());
            registerFunctionCallToSpecialForm(
                "try_cast", std::make_unique<SparkTryCastCallToSpecialForm>());
            exec::registerFunctionCallToSpecialForm(
                FromJsonCallToSpecialForm::kFromJson,
                std::make_unique<FromJsonCallToSpecialForm>());
            registerFunctionCallToSpecialForm(
                "get_struct_field", std::make_unique<GetStructFieldCallToSpecialForm>());
        }
    } // namespace sparksql
} // namespace kumo::pollux::functions
